namespace AdminSG3L.Domain.Entities;

/// <summary>
/// 所有实体的基类，包含主键、创建/更新时间、状态等通用字段
/// </summary>
public abstract class EntityBase
{
    /// <summary>
    /// 主键ID
    /// </summary>
    public Guid Id { get; set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsActive { get; set; } = true;
    /// <summary>
    /// 是否已删除
    /// </summary>
    public bool IsDeleted { get; set; } = false;
    /// <summary>
    /// 是否为系统数据（系统数据不可删除和修改）
    /// </summary>
    public bool IsSystem { get; set; } = false;
    /// <summary>
    /// 描述，可选
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 标记为已删除
    /// </summary>
    public void Delete()
    {
        if (IsSystem)
        {
            throw new InvalidOperationException("系统数据不允许删除");
        }
        IsDeleted = true;
    }

    /// <summary>
    /// 启用实体
    /// </summary>
    public void Enable()
    {
        IsActive = true;
    }

    /// <summary>
    /// 禁用实体
    /// </summary>
    public void Disable()
    {
        IsActive = false;
    }

    /// <summary>
    /// 更新时间为当前
    /// </summary>
    public void UpdateTime()
    {
        UpdatedAt = DateTime.UtcNow;
    }
}